﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataModel;

namespace Mvc4.Areas.Admin.Controllers
{
    public class SiteAttController : Controller
    {
        private ModelContainer db = new ModelContainer();

        //
        // GET: /Admin/SiteAtt/

        public ActionResult Index()
        {
            var siteattributeset = db.SiteAttributeSet.Include(s => s.SiteSet);
            return View(siteattributeset.ToList());
        }

        //
        // GET: /Admin/SiteAtt/Details/5

        public ActionResult Details(int id = 0)
        {
            SiteAttributeSet siteattributeset = db.SiteAttributeSet.Find(id);
            if (siteattributeset == null)
            {
                return HttpNotFound();
            }
            return View(siteattributeset);
        }

        //
        // GET: /Admin/SiteAtt/Create

        public ActionResult Create()
        {
            ViewBag.SiteId = new SelectList(db.SiteSet, "id", "Name");
            return View();
        }

        //
        // POST: /Admin/SiteAtt/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(SiteAttributeSet siteattributeset)
        {
            if (ModelState.IsValid)
            {
                db.SiteAttributeSet.Add(siteattributeset);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.SiteId = new SelectList(db.SiteSet, "id", "Name", siteattributeset.SiteId);
            return View(siteattributeset);
        }

        //
        // GET: /Admin/SiteAtt/Edit/5

        public ActionResult Edit(int id = 0)
        {
            SiteAttributeSet siteattributeset = db.SiteAttributeSet.Find(id);
            if (siteattributeset == null)
            {
                return HttpNotFound();
            }
            ViewBag.SiteId = new SelectList(db.SiteSet, "id", "Name", siteattributeset.SiteId);
            return View(siteattributeset);
        }

        //
        // POST: /Admin/SiteAtt/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(SiteAttributeSet siteattributeset)
        {
            if (ModelState.IsValid)
            {
                db.Entry(siteattributeset).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.SiteId = new SelectList(db.SiteSet, "id", "Name", siteattributeset.SiteId);
            return View(siteattributeset);
        }

        //
        // GET: /Admin/SiteAtt/Delete/5

        public ActionResult Delete(int id = 0)
        {
            SiteAttributeSet siteattributeset = db.SiteAttributeSet.Find(id);
            if (siteattributeset == null)
            {
                return HttpNotFound();
            }
            return View(siteattributeset);
        }

        //
        // POST: /Admin/SiteAtt/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            SiteAttributeSet siteattributeset = db.SiteAttributeSet.Find(id);
            db.SiteAttributeSet.Remove(siteattributeset);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}